package concurrent.customExecutor;

import utils.DateTimeUtils;

import java.util.Date;
import java.util.concurrent.LinkedBlockingQueue;

/**
 * Author: Jason Wu
 * Date  : 2013-11-27
 */
public class ThreadPoolMain {

    public static void main(String[] args) throws InterruptedException {
        LinkedBlockingQueue queue = new LinkedBlockingQueue();
        final DynamicThreadPoolExecutor dynamicThreadPool = new DynamicThreadPoolExecutor(queue, 5);
        System.out.println(String.format("Start:%s", DateTimeUtils.formatDate(new Date(), DateTimeUtils.DATE_TIME_FORMAT)));
        new Thread(new ExecuteThread(dynamicThreadPool)).start();

        Thread.sleep(10000);
        dynamicThreadPool.updateThreadCount(3);

        Thread.sleep(9000);
        dynamicThreadPool.updateThreadCount(6);

        Thread.sleep(7000);
        dynamicThreadPool.updateThreadCount(1);

        Thread.sleep(12000);
        dynamicThreadPool.updateThreadCount(4);

        Thread.sleep(13000);
        dynamicThreadPool.updateThreadCount(5);

        Thread.sleep(7000);
        dynamicThreadPool.updateThreadCount(7);

        Thread.sleep(11000);
        dynamicThreadPool.updateThreadCount(3);
    }
}
